<?php session_start(); if($_SESSION['properlogin'] != 1){ header("Location:error.html"); } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Information</title>
<script type="text/javascript" src="validateInformation.js" ></script>


<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>

<body>
<table width="100%" border="0" cellpadding="1">
 
  <tr>
    <td>&nbsp;</td>
    <td class="subBanner"><strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Check-Out Resident</strong></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><form id="form1" name="form1" method="post" action="" >
      <table width="100%" border="0" cellpadding="1">
        <tr>
          <td width="34%">&nbsp;</td>
          <td class=confirm1 width="43%">Enter Student Number</td>
          <td width="23%" class="error" id="lname">&nbsp;</td>
        </tr>
        <tr>
          <td >&nbsp;</td>
          <td class=confirm1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="outNum" type="text" id="outNum" size="4" />
            -
  <input name="outNum2" type="text" id="outNum2" size="10" /></td>
          <td >&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td class="confirm1" width="43%">Current User Password</td>
          <td >&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td class="confirm1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="pword" type="password" id="pword" size="40" /></td>
          <td >&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td >&nbsp;</td>
          <td >&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td ><span class="confirm">
            <input name="Submit" type="Submit" value="TEMPORARY Check out"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;</td>
          <td >&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td ><span class="confirm">
            <input name="Submit" type="Submit" value="PERMANENT Check out"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;</td>
          <td >&nbsp;</td>
        </tr>
        </table>
    </form>
    
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

   <?php
		require_once 'CheckoutView.php';
		if(isset($_POST['Submit'])){
			
			if($_POST['Submit'] == "PERMANENT Check out"){
			$snum = $_POST['outNum'].$_POST['outNum2'];
			$userPword = $_POST['pword'];
			
			
			if($snum!=" "&&$snum!=""&&$userPword!=" "&&$userPword!=""){
				
					if(strcmp($userPword,$_SESSION['password']) != 0){
						echo "<script>alert(\"Authentication failed!\\n\\nCaps Lock is ON ?\")</script>";
					}else{
					
					//The user can now delete the student, if it exists
						$flag1 = CheckoutView::searchStudent($snum);
							
							if($flag1==0){//Student number doesnt exist from CHECK_IN table
								echo"<script>alert(\"Student Not Found!\")</script>";
								
							}else{//Student number exist CHECK_IN table
								echo"<script>
									var flag = confirm(\"User ".$_SESSION['username']." authenticated. \\n\\nAre you sure you want to check-out ".$_POST['outNum']."-".$_POST['outNum2']."? \\n\\nThis will erase ALL entries of this student number in the Resident Database.\")
									if(flag){
											location=\"checkoutConfirm.php?flag=1&mode=perm&snum=".$snum."\"; 
									}else{
											location=\"checkoutConfirm.php?flag=0\"; 
								}
								</script>";
						}
					}
			}else{
				echo"<script>alert(\"Please enter Student Number!\")</script>";
			}
			}else if($_POST['Submit'] == "TEMPORARY Check out"){
				

				
				
				$snum = $_POST['outNum'].$_POST['outNum2'];
			$userPword = $_POST['pword'];
			
			
			if($snum!=" "&&$snum!=""&&$userPword!=" "&&$userPword!=""){
				
					if(strcmp($userPword,$_SESSION['password']) != 0){
						echo "<script>alert(\"Authentication failed!\\n\\nCaps Lock is ON ?\")</script>";
					}else{
					
					//The user can now delete the student, if it exists
						$flag1 = CheckoutView::searchStudent($snum);
							
							if($flag1==0){//Student number doesnt exist from CHECK_IN table
								echo"<script>alert(\"Student Not Found!\")</script>";
								
							}else{//Student number exist CHECK_IN table
								echo"<script>
									var flag = confirm(\"User ".$_SESSION['username']." authenticated. \\n\\nAre you sure you want to check-out ".$_POST['outNum']."-".$_POST['outNum2']."? \\n\\nThis will update Check out date entry of this student number in the Resident Database.\")
									if(flag){
											location=\"checkoutConfirm.php?flag=1&mode=temp&snum=".$snum."\"; 
									}else{
											location=\"checkoutConfirm.php?flag=0\"; 
								}
								</script>";
						}
					}
			}else{
				echo"<script>alert(\"Please enter Student Number!\")</script>";
			}
			
			
			}
	}

	?>

